package com.xb.p4_widgets;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;

public class ProcessBarActivity extends AppCompatActivity {

    private Handler handler=new Handler();
    private ProgressBar progressBar;

    private  int i=0;

    private Runnable runnable =new Runnable() {
        @Override
        public void run() {
            i++;
            if(i==100){
                handler.removeCallbacks(this);
            }
            progressBar.setProgress(i);
            handler.postDelayed(this,100);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_process_bar);

        progressBar=findViewById(R.id.pgbar_test);

        //开始进度条
        handler.postDelayed(runnable,100);
    }
}
